package moonstruckdrops.datastore.provider;

import java.io.Serializable;
import java.util.Iterator;

import moonstruckdrops.dao.EntryDao;
import moonstruckdrops.dto.EntryDto;

import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public class BlogEntoryProvider implements IDataProvider<EntryDto>,Serializable{
	private static final long serialVersionUID = 1L;

	transient EntryDao dao;

	public Iterator<? extends EntryDto> iterator(int first,int count) {
		resolveDao();
		return dao.getEntry(first,count).iterator();
	}

	public int size() {
		resolveDao();
		return dao.EntrySize();
	}

	public IModel<EntryDto> model(EntryDto object) {
		return new Model<EntryDto>(object);
	}

	public void detach() {
	}

	void resolveDao() {
		if(dao == null) {
			dao = new EntryDao();
		}
	}
}
